<template>
  <page class="actapply-audit">
    <page-header>
      <x-header :left-options="{backText: ''}">确认收货</x-header>
    </page-header>
    <page-content :scroll="true" @refresh="refresh" @infinite="infinite">
      <group>
        <x-textarea :max="50" :placeholder="'处理意见'" :height="100" v-model="form.auditText"></x-textarea>
      </group>
    </page-content>
    <page-footer>
      <div class="fix">
        <button class="qued" @click='handleClick()'>提交</button>
      </div>
    </page-footer>
  </page>
</template>

<script>
import { mapGetters } from 'vuex'
import { XHeader, XTextarea, Group, XInput } from 'vux'
import { actApply } from '@service'
import { MessageBox } from 'mint-ui'

export default {
  name: 'ActApplyAudit',
  components: {
    XHeader,
    XTextarea,
    Group,
    XInput
  },
  computed: {
    ...mapGetters({
      userInfo: 'user/info',
      token: 'user/token',
      taskInfo: 'task/info'
    }),
    userId () {
      return this.userInfo.id
    }
  },
  data () {
    return {
      form: {
        auditText: ''
      }
    }
  },
  methods: {
    handleClick (id) {
      this.commit()
    },
    async commit () {
      let userId = this.userId
      let token = this.token
      let applyId = this.taskInfo['actApply.id']
      let allotId = this.taskInfo['actAllot.id']
      let taskId = this.taskInfo['task.id']
      let taskDefKey = this.taskInfo['task.taskDefinitionKey']
      let procInsId = this.taskInfo['task.processInstanceId']
      let { auditText } = this.form
      let flag = 'yes'
      try {
        if (!auditText) {
          MessageBox.alert('请输入处理意见')
          return
        }
        let data = await actApply.saveAudit({
          userId,
          token,
          applyId,
          allotId,
          taskId,
          taskDefKey,
          procInsId,
          auditText,
          flag
        })
        console.log(data)
        MessageBox.alert('处理成功')
        await this.$store.dispatch('task/updateTaskStatus', true)
        this.$router.go(-3)
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style lang="scss">
.actapply-audit {
  .right {
    line-height: 2rem;
  }

  .scroller-box {
    padding: 1rem;
  }

  .qued {
    width: 100%;
    height: 3rem;
    background: #4a82c6;
    border: none;
    color: #fff;
  }
}
</style>
